package main

import "fmt"

func main() {
	s, t := "paper", "title"
	fmt.Println(isIsomorphic(s, t))
}

func isIsomorphic(s string, t string) bool {
	d := make(map[byte]byte)
	r := make(map[byte]byte)
	for i := 0; i < len(s); i++ {
		if v, ok := d[s[i]]; ok {
			if t[i] != v {
				return false
			}
		} else {
			if v, ok := d[t[i]]; ok && t[i] == v {
				return false
			}

			if v, ok := r[t[i]]; ok && t[i] != v {
				return false
			}
			r[t[i]] = s[i]
			d[s[i]] = t[i]
		}
	}

	return true
}
